<script setup lang="ts">
import {
  DataBoard,
  Menu,
  Reading,
  ChatLineRound,
  EditPen,
  User
} from "@element-plus/icons-vue"
import type { MenuItem } from './types'

// 定义props类型
interface Props {
  fold?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  fold: false
})

// 菜单配置项
const menuItems: MenuItem[] = [
  {
    path: '/dashboard',
    title: '控制台',
    icon: DataBoard
  },
  {
    path: '/cate',
    title: '分类管理',
    icon: Menu
  },
  {
    path: '/book',
    title: '图书管理',
    icon: Reading
  },
  {
    path: '/review',
    title: '书评管理',
    icon: ChatLineRound
  },
  {
    path: '/note',
    title: '笔记管理',
    icon: EditPen
  },
  {
    path: '/user',
    title: '用户管理',
    icon: User
  }
]
</script>

<template>
  <el-aside 
    :width="props.fold ? '64px' : '200px'"
    class="sidebar-container"
  >
    <el-menu
      :default-active="$route.path"
      active-text-color="#3f72af"
      background-color="#112d4e"
      text-color="#dbe2ef"
      :collapse="props.fold"
      :collapse-transition="false"
      router
    >
      <template v-for="item in menuItems" :key="item.path">
        <el-menu-item :index="item.path">
          <el-icon>
            <component :is="item.icon" />
          </el-icon>
          <template #title>
            <span class="menu-title">{{ item.title }}</span>
          </template>
        </el-menu-item>
      </template>
    </el-menu>
  </el-aside>
</template>

<style lang="scss" scoped>
.sidebar-container {
  background-color: #112d4e;
  transition: width 0.3s ease;
  height: 100vh;
  position: relative;
  z-index: 10;
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.15);

  .el-menu {
    border-right: none;
    height: 100%;

    &:not(.el-menu--collapse) {
      width: 100%;
    }

    .menu-title {
      font-weight: 600;
      margin-left: 8px;
    }

    .el-menu-item {
      transition: background-color 0.3s;
      position: relative;
      height: 48px;
      line-height: 48px;

      &:hover {
        background-color: rgba(255, 255, 255, 0.1) !important;
      }

      &.is-active {
        font-weight: bold;
        background-color: #dbe2ef !important;
        color: #112d4e !important;

        .menu-title {
          color: #112d4e;
        }

        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 50%;
          transform: translateY(-50%);
          width: 3px;
          height: 24px;
          background-color: #3f72af;
          border-radius: 0 3px 3px 0;
        }
      }
    }
  }
}
</style>